package Example1;

import javax.jnlp.FileContents;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.*;

@WebServlet("/Example3")
@MultipartConfig
public class Example3 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html; charset=utf-8");
        req.setCharacterEncoding("utf8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String workplace = req.getParameter("workplace");
        Part part = req.getPart("myFile");

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("username: "+ username);
        stringBuilder.append("<br>");
        stringBuilder.append("password: "+ password);
        stringBuilder.append("<br>");
        stringBuilder.append("workplace: "+ workplace);
        stringBuilder.append("<br>");
        stringBuilder.append("图片名称: "+ part.getSubmittedFileName());
        stringBuilder.append("<br>");
        stringBuilder.append("欢迎!");
        resp.getWriter().write(stringBuilder.toString());

        System.out.println("username: "+ username);
        System.out.println("password: "+ password);
        System.out.println("workplace: "+ workplace);
        System.out.println("image: "+ part.getSubmittedFileName());
        System.out.println("欢迎!");

    }
}
